<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0"><meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />   
        <title>Welcome to Design Zone......</title>
        <link rel="stylesheet" type="text/css" href="../../scripts/ext/resources/css/ext-all.css" />
		<link rel="stylesheet" type="text/css" href="../../scripts/ext/resources/css/file-upload.css" />
        <link rel="stylesheet" type="text/css" href="../../styles/dzbase.css" />
        <script type="text/javascript" src="../../scripts/ext/adapter/ext-base.js">
        </script>
        <script type="text/javascript" src="../../scripts/ext/ext-all.js">
        </script>
        <script type="text/javascript" src="../../scripts/menu/EditableItem.js">
        </script>
        <script type="text/javascript" src="../../scripts/menu/RangeMenu.js">
        </script>
        <script type="text/javascript" src="../../scripts/grid/GridFilters.js">
        </script>
        <script type="text/javascript" src="../../scripts/grid/filter/Filter.js">
        </script>
        <script type="text/javascript" src="../../scripts/grid/filter/StringFilter.js">
        </script>
		<script type="text/javascript" src="../../scripts/form/FileUploadField.js">
        </script>
        <script type="text/javascript" src="../../scripts/i18nMessage.js">
        </script>
        <script type="text/javascript" src="../../scripts/selectBiFranceCustomer.js">
        </script>
        <script type="text/javascript" src="../../scripts/utils.js">
        </script>
        <script type="text/javascript">
            var sketchMessage = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=ui.sketch');
            var message = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=message');
            var fcMessage = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=ui.francecustomer');
            
			var ctSketchTypeXmlLoader = new xmlLoader('../../servlet/CodeTableServlet?name=CtSketchType');
			var ctCollarTypeXmlLoader = new xmlLoader('../../servlet/CodeTableServlet?name=CtCollarType');
			var ctSeasonNumberXmlLoader = new xmlLoader('../../servlet/CodeTableServlet?name=CtSeasonNumber');
			
			var ctSketchTypeStore;
			var ctCollarTypeStore;
			var ctSeasonNumberStore;
			
			var ctSketchTypeCombo;
			var ctCollarTypeCombo;
			var ctSeasonNumberCombo;
			
			var setReference = function(){
				if(ctSketchTypeCombo.getValue() == null || ctSketchTypeCombo.getValue() == ''){
					return;
				}
				if(ctCollarTypeCombo.getValue() == null || ctCollarTypeCombo.getValue() == ''){
					return;
				}
				var sketch = ctSketchTypeCombo.getRawValue();
				var collar = ctCollarTypeCombo.getRawValue();
				var maxReferenceIndextXmlLoader = new xmlLoader('../../servlet/BiSketchServlet?action=10&ctSketchType=' + ctSketchTypeCombo.getValue() + '&ctCollarType=' + ctCollarTypeCombo.getValue());
				var maxIndex = maxReferenceIndextXmlLoader.getValueByTagName('item');
				//alert(maxIndex);
				document.getElementById('referenceIndex').value = maxIndex;
				document.getElementById('reference').value = 'CP' + '-' + sketch.substring(sketch.length-2) + '-' + collar.substring(collar.length-1) + '-' + maxIndex;
			}
			var selectFranceCustomerCallback = function(customerId, customerName, customerDepartment){
                document.getElementById('customerId').value = customerId;
                document.getElementById('customerName').value = customerName;
                document.getElementById('customerDepartment').value = customerDepartment;
            }
            Ext.onReady(function(){
                Ext.QuickTips.init();
                
                Ext.form.Field.prototype.msgTarget = 'side';
                
                var idValue = getPrarmeterValue(window.location, 'id');
                var startPage = getPrarmeterValue(window.location, 'startPage');
                
                var idValue = getPrarmeterValue(window.location, 'id');
                var startPage = getPrarmeterValue(window.location, 'startPage');
				
				ctSketchTypeStore = new Ext.data.Store({
                   
                    reader: new Ext.data.XmlReader({
                        record: 'item',
                        id: 'code',
                        totalRecords: 'itemTotal'
                    }, [
                    'code', 'description']),
					data: ctSketchTypeXmlLoader.getXml()
                });
				
				ctCollarTypeStore = new Ext.data.Store({
                   
                    reader: new Ext.data.XmlReader({
                        record: 'item',
                        id: 'code',
                        totalRecords: 'itemTotal'
                    }, [
                    'code', 'description']),
					data: ctCollarTypeXmlLoader.getXml()
                });

				ctSeasonNumberStore = new Ext.data.Store({
	                   
                    reader: new Ext.data.XmlReader({
                        record: 'item',
                        id: 'code',
                        totalRecords: 'itemTotal'
                    }, [
                    'code', 'description']),
					data: ctSeasonNumberXmlLoader.getXml()
                });
				
				ctSketchTypeCombo = new Ext.form.ComboBox({
					fieldLabel: sketchMessage.get('ui.sketch.type'),
					id: 'ctSketchType',
					name: 'ctSketchType',
					allowBlank: false,
                    blankText: message.get('message.edit.noblank'),
					editable: false,
					valueField: 'code',
				    store: ctSketchTypeStore,
				    displayField:'description',
				    triggerAction: 'all',
				    emptyText: message.get('message.combo.pleaseselect'),
				    selectOnFocus:true,
					mode: 'local',
					listeners: {
						select: {
							fn: function (thisCombo, record,index){
								//setReference();
							}
						}
					}
				});
				
				ctCollarTypeCombo = new Ext.form.ComboBox({
					fieldLabel: message.get('message.edit.collar'),
					id: 'ctCollarType',
					name: 'ctCollarType',
					allowBlank: false,
                    blankText: message.get('message.edit.noblank'),
					editable: false,
					valueField: 'code',
				    store: ctCollarTypeStore,
				    displayField:'description',
				    triggerAction: 'all',
				    emptyText: message.get('message.combo.pleaseselect'),
				    selectOnFocus:true,
					mode: 'local',
					listeners: {
						select: {
							fn: function (thisComb, record,index){
								//setReference();
							}
						}
					}
				});

				ctSeasonNumberCombo = new Ext.form.ComboBox({
					fieldLabel: message.get('message.edit.seasonnumber'),
					id: 'ctSeasonNumber',
					name: 'ctSeasonNumber',
					allowBlank: false,
                    blankText: message.get('message.edit.noblank'),
					editable: false,
					valueField: 'code',
				    store: ctSeasonNumberStore,
				    displayField:'description',
				    triggerAction: 'all',
				    emptyText: message.get('message.combo.pleaseselect'),
				    selectOnFocus:true,
					mode: 'local',
					anchor: '90%'
				});
				
                var sketchForm = new Ext.FormPanel({
					fileUpload: true,
                    labelAlign: 'left',
                    url: '../../servlet/BiSketchServlet?action=1',
                    frame: true,
                    title: sketchMessage.get('ui.sketch.edittitle'),
                    bodyStyle: 'padding:5px 5px 5px 5px;margin-top: 2px;',
                    width: '100%',
                    labelWidth: 105,
                    reader: new Ext.data.XmlReader({
                        record: 'item'
                    }, [{
                        name: 'id',
                        mapping: 'id'
                    },{
						name: 'reference',
						mapping: 'reference'
					},{
						name: 'referenceIndex',
						mapping: 'referenceIndex'
					},{
						name: 'ctSketchType',
						mapping: 'ctSketchType'
					},{
						name: 'ctCollarType',
						mapping: 'ctCollarType'
					},{
						name: 'photo1Name',
						mapping: 'photo1Name'
					},{
						name: 'photo2Name',
						mapping: 'photo2Name'
					},{
						name: 'photo3Name',
						mapping: 'photo3Name'
					},{
						name: 'photo4Name',
						mapping: 'photo4Name'
					},{
						name: 'commentFr',
						mapping: 'commentFr'
					},{
						name: 'commentEn',
						mapping: 'commentEn'
					},{
						name: 'commentCn',
						mapping: 'commentCn'
					},{
						name: 'customerId',
						mapping: 'customerId'
					},{
						name: 'customerName',
						mapping: 'customerName'
					},{
						name: 'customerDepartment',
						mapping: 'customerDepartment'
					},{
						name: 'ctSeasonNumber',
						mapping: 'ctSeasonNumber'
					}]),
                    items: [{
                        id: 'id',
                        name: 'id',
                        xtype: 'hidden'
                    },{
                        id: 'referenceIndex',
                        name: 'referenceIndex',
                        xtype: 'hidden'
                    },{
                        id: 'photo1Name',
                        name: 'photo1Name',
                        xtype: 'hidden'
                    },{
                        id: 'photo2Name',
                        name: 'photo2Name',
                        xtype: 'hidden'
                    },{
                        id: 'photo3Name',
                        name: 'photo3Name',
                        xtype: 'hidden'
                    },{
                        id: 'photo4Name',
                        name: 'photo4Name',
                        xtype: 'hidden'
                    },{
                        id: 'customerId',
                        name: 'customerId',
                        xtype: 'hidden'
                    }, {
							layout: 'column',
							items: [{
								columnWidth:.3,
				                layout: 'form',
								items: [ctSketchTypeCombo,{
	                                id: 'customerName',
	                                name: 'customerName',
	                                fieldLabel: message.get('message.edit.customername'),
	                                xtype: 'textfield',
	                                anchor: '86%',
	                                allowBlank: false,
	                                blankText: message.get('message.edit.noblank'),
	                                emptyText: message.get('message.combo.pleaseselect'),
	                                readOnly: true,
	                                maxLength: 64,
	                                listeners: {
	                                    'render': {
	                                        fn: function(){
	                                            Ext.getCmp('customerName').getEl().on('click', function(){
	                                                selectFranceCustomer(selectFranceCustomerCallback);
	                                            }, this);
	                                        },
	                                        scope: this
	                                    }
	                                }
	                            }]
							},{
								columnWidth:.3,
				                layout: 'form',
								items: [ctCollarTypeCombo,{
	                                xtype: 'textfield',
	                                fieldLabel: fcMessage.get('ui.francecustomer.department'),
	                                id: 'customerDepartment',
	                                name: 'customerDepartment',
	                                anchor: '86%',
	                                allowBlank: true,
	                                blankText: message.get('message.edit.noblank'),
	                                readOnly: true,
	                                maxLength: 64,
	                                tabIndex: 1
	                            }]
							},{
								columnWidth:.3,
				                layout: 'form',
								items: [ctSeasonNumberCombo]
							}]
                    }, {
						name: 'reference',
                        id: 'reference',
                        fieldLabel: message.get('message.edit.reference'),
                        xtype: 'textfield',
                        anchor: '86%',
                        allowBlank: false,
                        blankText: message.get('message.edit.noblank'),
                        maxLength: 64
					},{
						xtype: 'fileuploadfield',
						width: '80%',
			            id: 'photo1',
						name: 'photo1',
			            emptyText: message.get('message.edit.selectimage'),
			            fieldLabel: message.get('message.edit.photo') + '1',
			            buttonCfg: {
			                text: '',
			                iconCls: 'uploadIcon'
		            	}
					},{
						xtype: 'fileuploadfield',
						width: '80%',
			            id: 'photo2',
						name: 'photo2',
			            emptyText: message.get('message.edit.selectimage'),
			            fieldLabel: message.get('message.edit.photo') + '2',
			            buttonCfg: {
			                text: '',
			                iconCls: 'uploadIcon'
		            	}
					},{
						xtype: 'fileuploadfield',
						width: '80%',
			            id: 'photo3',
						name: 'photo3',
			            emptyText: message.get('message.edit.selectimage'),
			            fieldLabel: message.get('message.edit.photo') + '3',
			            buttonCfg: {
			                text: '',
			                iconCls: 'uploadIcon'
		            	}
					},{
						xtype: 'fileuploadfield',
						width: '80%',
			            id: 'photo4',
						name: 'photo4',
			            emptyText: message.get('message.edit.selectimage'),
			            fieldLabel: message.get('message.edit.photo') + '4',
			            buttonCfg: {
			                text: '',
			                iconCls: 'uploadIcon'
		            	}
					},{
						fieldLabel: message.get('message.edit.descriptionfr'),
                        name: 'commentFr',
                        xtype: 'textarea',
                        maxLength: 512,
						width: '90%',
                        maxLengthText: message.get('message.edit.toolong')
					},{
						fieldLabel: message.get('message.edit.descriptioncn'),
                        name: 'commentCn',
                        xtype: 'textarea',
                        maxLength: 512,
						width: '90%',
                        maxLengthText: message.get('message.edit.toolong')
					},{
						fieldLabel: message.get('message.edit.descriptionen'),
                        name: 'commentEn',
                        xtype: 'textarea',
                        maxLength: 512,
						width: '90%',
                        maxLengthText: message.get('message.edit.toolong')
					}],
                    
                    buttons: [{
                        text: message.get('message.edit.save'),
                        handler: function(){
                            if (sketchForm.getForm().isValid()) {
                            	
                            	if(idValue == null){
                            		//setReference();
                            	}
                            	
								document.getElementsByName('ctSketchType')[0].value = ctSketchTypeCombo.getValue();
								document.getElementsByName('ctCollarType')[0].value = ctCollarTypeCombo.getValue();
								document.getElementsByName('ctSeasonNumber')[0].value = ctSeasonNumberCombo.getValue();
								
                                sketchForm.getForm().submit({
                                    method: 'post',
                                    success: function(form, action){
                                        messageTip.msg(message.get('message.tip'), message.get('message.edit.successful'));
                                        document.getElementById('photo1-file').value = null;
										document.getElementById('photo2-file').value = null;
										document.getElementById('photo3-file').value = null;
										document.getElementById('photo4-file').value = null;
                                        sketchForm.getForm().reset();
                                    },
                                    failure: function(form, action){
                                        messageTip.msg(message.get('message.tip'), message.get('message.edit.unsuccessful'));
                                    }
                                });
                            }
                        }
                    }, {
                        text: message.get('message.edit.reset'),
                        handler: function(){
                            sketchForm.getForm().reset();
                        }
                    }, {
                        text: message.get('message.edit.cancel'),
                        handler: function(){
                            if (startPage != null) {
                                window.location = 'sketch_list.html?startPage=' + startPage;
                            }
                            else {
                                window.location = 'sketch_list.html';
                            }
                        }
                    }]
                })
                
                sketchForm.render('armorDiv');
				
				new Ext.Resizable('customImg', {
                    wrap: true,
                    pinned: true,
                    dynamic: true,
                    handles: 'all',
                    draggable: true
                });
                
                new Ext.Resizable('customImg1', {
                    wrap: true,
                    pinned: true,
                    dynamic: true,
                    handles: 'all',
                    draggable: true
                });
				
				new Ext.Resizable('customImg2', {
                    wrap: true,
                    pinned: true,
                    dynamic: true,
                    handles: 'all',
                    draggable: true
                });
                
                new Ext.Resizable('customImg3', {
                    wrap: true,
                    pinned: true,
                    dynamic: true,
                    handles: 'all',
                    draggable: true
                });
                
                if (idValue != null) {
                    document.getElementById('id').value = idValue;
                    sketchForm.getForm().load({
                        url: '../../servlet/BiSketchServlet?action=3&id=' + idValue,
                        waitMsg: Ext.LoadMask.prototype.msg,
                        success: function(form, action){
                            document.getElementById('customImg').src =  '../../_temp/' + document.getElementById('photo1Name').value;
							document.getElementById('customImg1').src =  '../../_temp/' + document.getElementById('photo2Name').value;
							document.getElementById('customImg2').src =  '../../_temp/' + document.getElementById('photo3Name').value;
							document.getElementById('customImg3').src =  '../../_temp/' + document.getElementById('photo4Name').value;
                        }
                    });
                }
                
            });
        </script>
    </head>
    <body>
        <div id="armorDiv">
        </div>
		<img id="customImg" src="../../_temp/noimage.gif" style="position:absolute;left: 0%;width: 250px;"/>
		<img id="customImg1" src="../../_temp/noimage.gif" style="position:absolute;left: 25%;width: 250px;"/>
		<img id="customImg2" src="../../_temp/noimage.gif" style="position:absolute;left: 50%;width: 250px;"/>
		<img id="customImg3" src="../../_temp/noimage.gif" style="position:absolute;left: 75%;width: 250px;"/>
    </body>
</html>
